package com.yuntsg.subject_database.util;

import co.elastic.clients.elasticsearch.ElasticsearchClient;
import co.elastic.clients.elasticsearch.indices.CreateIndexResponse;
import com.yuntsg.subject_database.entity.IndexConfig;

public class ArticleIndex {

    public static void main(String[] args) throws Exception {
        start();

    }

    public static void start() throws Exception {


        // 创建连接
        ElasticsearchClient client = EsClient.client();
        CreateIndexResponse createIndexResponse = client.indices().create(c -> c.index(IndexConfig.ARTICLE_INDEX).settings(indexSettingsBuilder -> indexSettingsBuilder.numberOfReplicas("1").numberOfShards("8"))
                .mappings(
                        o -> o.properties("py", i -> i.integer(k -> k))
                                .properties("mesh", i -> i.text(p -> p
                                        .analyzer("english")
                                        .searchAnalyzer("english")
                                        .fields("suggest", l -> l.completion(u -> u.analyzer("english")))
                                        .fields("wildcard", v -> v.wildcard(a -> a))
                                        .fields("keyword", r -> r.keyword(m -> m.normalizer("lowercase")))
                                ))

                                .properties("enkw", i -> i.text(p -> p.
                                        analyzer("english")
                                        .searchAnalyzer("english")
                                        .fields("suggest", l -> l.completion(u -> u.analyzer("english")))
                                        .fields("wildcard", v -> v.wildcard(a -> a))
                                        .fields("keyword", r -> r.keyword(m -> m.normalizer("lowercase")))))


                                .properties("cnkw", i -> i.text(p -> p
                                        .analyzer("ik_max_word")
                                        .searchAnalyzer("ik_max_word")
                                        .fields("suggest", l -> l.completion(u -> u.analyzer("english")))
                                        .fields("wildcard", v -> v.wildcard(a -> a))
                                        .fields("keyword", r -> r.keyword(m -> m.normalizer("lowercase")))))

                                .properties("enfau", i -> i.text(p -> p
                                        .analyzer("english")
                                        .searchAnalyzer("english")
                                        .fields("wildcard", v -> v.wildcard(a -> a))

                                ))

                                .properties("cnfau", i -> i.text(p -> p
                                        .analyzer("ik_max_word")
                                        .searchAnalyzer("ik_max_word")
                                        .fields("wildcard", v -> v.wildcard(a -> a))

                                ))

                                .properties("encau", i -> i.text(p -> p
                                        .analyzer("english")
                                        .searchAnalyzer("english")
                                        .fields("wildcard", v -> v.wildcard(a -> a))
                                        .fields("keyword", r -> r.keyword(m -> m.normalizer("lowercase")))))

                                .properties("cncau", i -> i.text(p -> p
                                        .analyzer("ik_max_word")
                                        .searchAnalyzer("ik_max_word")
                                        .fields("wildcard", v -> v.wildcard(a -> a))
                                        .fields("keyword", r -> r.keyword(m -> m.normalizer("lowercase")))))

                                .properties("pg", i -> i.keyword(p -> p))

                                .properties("vl", i -> i.keyword(p -> p))

                                .properties("issue", i -> i.keyword(p -> p))

                                .properties("dt", i -> i.keyword(p -> p))

                                .properties("cnau", i -> i.text(p -> p
                                        .analyzer("ik_max_word")
                                        .searchAnalyzer("ik_max_word")
                                        .fields("wildcard", v -> v.wildcard(a -> a))
                                        .fields("keyword", r -> r.keyword(m -> m.normalizer("lowercase")))))

                                .properties("cndept", i -> i.text(p -> p
                                        .analyzer("ik_max_word")
                                        .searchAnalyzer("ik_max_word")
                                        .fields("wildcard", v -> v.wildcard(a -> a))
                                        .fields("keyword", r -> r.keyword(m -> m.normalizer("lowercase")))))

                                .properties("endept", i -> i.text(p -> p
                                        .analyzer("english")
                                        .searchAnalyzer("english")
                                        .fields("wildcard", v -> v.wildcard(a -> a))
                                        .fields("keyword", r -> r.keyword(m -> m.normalizer("lowercase")))))

                                .properties("cnfund", i -> i.text(p -> p
                                        .analyzer("ik_max_word")
                                        .searchAnalyzer("ik_max_word")
                                        .fields("wildcard", v -> v.wildcard(a -> a))

                                ))

                                .properties("enfund", i -> i.text(p -> p
                                        .analyzer("english").searchAnalyzer("english")
                                        .fields("wildcard", v -> v.wildcard(a -> a))

                                ))

                                .properties("cnta", i -> i.text(p -> p
                                        .analyzer("ik_max_word")
                                        .searchAnalyzer("ik_max_word")
                                        .fields("wildcard", v -> v.wildcard(a -> a))
                                        .fields("keyword", r -> r.keyword(m -> m.normalizer("lowercase")))))

                                .properties("enau", i -> i.text(p -> p
                                        .analyzer("english")
                                        .searchAnalyzer("english")
                                        .fields("wildcard", v -> v.wildcard(a -> a))
                                        .fields("keyword", r -> r.keyword(m -> m.normalizer("lowercase")))))

                                .properties("enta", i -> i.text(p -> p
                                        .analyzer("english")
                                        .searchAnalyzer("english")
                                        .fields("wildcard", v -> v.wildcard(a -> a))
                                        .fields("keyword", r -> r.keyword(m -> m.normalizer("lowercase")))))

                                .properties("mh", i -> i.text(p -> p
                                        .analyzer("english")
                                        .searchAnalyzer("english")
                                        .fields("suggest", l -> l.completion(u -> u.analyzer("english")))
                                        .fields("wildcard", v -> v.wildcard(a -> a))
                                        .fields("keyword", r -> r.keyword(m -> m.normalizer("lowercase")))))

                                .properties("sh", i -> i.text(p -> p
                                        .analyzer("english")
                                        .searchAnalyzer("english")
                                        .fields("suggest", l -> l.completion(u -> u.analyzer("english")))
                                        .fields("wildcard", v -> v.wildcard(a -> a))
                                        .fields("keyword", r -> r.keyword(m -> m.normalizer("lowercase")))))

                                .properties("sn", i -> i.keyword(p -> p))
                                .properties("dataunique", i -> i.keyword(p -> p))
                                .properties("doi", i -> i.keyword(q -> q))

                                .properties("enti", i -> i.text(p -> p
                                        .analyzer("ik_max_word")
                                        .searchAnalyzer("ik_max_word")
                                        .fields("suggest", l -> l.completion(u -> u.analyzer("english")))
                                        .fields("wildcard", v -> v.wildcard(a -> a))
                                        .fields("keyword", r -> r.keyword(m -> m.normalizer("lowercase")))))

                                .properties("cnti", i -> i.text(p -> p
                                        .analyzer("ik_max_word")
                                        .searchAnalyzer("ik_max_word")
                                        .fields("suggest", l -> l.completion(u -> u.analyzer("ik_max_word")))
                                        .fields("wildcard", v -> v.wildcard(a -> a))
                                        .fields("keyword", r -> r.keyword(m -> m.normalizer("lowercase")))))


                                .properties("enab", i -> i.text(p -> p
                                        .analyzer("english")
                                        .searchAnalyzer("english")
                                        .fields("wildcard", v -> v.wildcard(a -> a))))

                                .properties("cnab", i -> i.text(p -> p
                                        .analyzer("ik_max_word")
                                        .searchAnalyzer("ik_max_word")
                                        .fields("wildcard", v -> v.wildcard(a -> a))))

                                .properties("enad", i -> i.text(p -> p
                                        .analyzer("english")
                                        .searchAnalyzer("english")

                                        .fields("wildcard", v -> v.wildcard(a -> a))))

                                .properties("enunit", i -> i.text(p -> p
                                        .analyzer("english").searchAnalyzer("english")
                                        .fields("keyword", r -> r.keyword(m -> m))
                                        .fields("wildcard", v -> v.wildcard(a -> a))))

                                .properties("cnunit", i -> i.text(p -> p
                                        .analyzer("ik_max_word")
                                        .searchAnalyzer("ik_max_word")
                                        .fields("keyword", r -> r.keyword(m -> m))
                                        .fields("wildcard", v -> v.wildcard(a -> a))))

                                .properties("cnad", i -> i.text(p -> p
                                        .analyzer("ik_max_word")
                                        .searchAnalyzer("ik_max_word")
                                        .fields("wildcard", v -> v.wildcard(a -> a))))

                                .properties("la", i -> i.keyword(p -> p))
                                .properties("cnts", i -> i.text(p -> p.analyzer("ik_max_word").searchAnalyzer("ik_max_word").fields("keyword", r -> r.keyword(m -> m.normalizer("lowercase")))))

                                .properties("ents", i -> i.text(p -> p.analyzer("english").searchAnalyzer("english")))
                                .properties("citescore", i -> i.double_(p -> p))
                                .properties("scieif", i -> i.double_(k -> k))
                                .properties("sjrscore", i -> i.double_(p -> p))
                                .properties("citationquota", i -> i.double_(p -> p))


                                .properties("referencequota", i -> i.double_(p -> p))
                                .properties("id", i -> i.integer(p -> p))
                                .properties("articleid", i -> i.keyword(p -> p))
                                .properties("dataid", i -> i.integer(p -> p))
                                .properties("jid", i -> i.integer(p -> p))

                                .properties("ispdf", i -> i.integer(p -> p))
                                .properties("issixj", i -> i.integer(p -> p))
                                .properties("iszhonghua", i -> i.integer(p -> p))
                                .properties("isbeida", i -> i.integer(p -> p))
                                .properties("istongjiyuan", i -> i.integer(p -> p))

                                .properties("iscscd", i -> i.integer(p -> p))
                                .properties("iszky", i -> i.integer(p -> p))
                                .properties("ispubmed", i -> i.integer(p -> p))
                                .properties("iscite", i -> i.integer(p -> p))
                                .properties("iswfmed", i -> i.integer(p -> p))

                                .properties("ischkd", i -> i.integer(p -> p))
                                .properties("altmetric", i -> i.integer(p -> p))
                                .properties("citationnum", i -> i.integer(p -> p))
                                .properties("referencenum", i -> i.integer(p -> p))
                                .properties("zkydalei", i -> i.keyword(p -> p))

                                .properties("zkysubject", i -> i.keyword(p -> p))
                                .properties("pubtype", i -> i.keyword(p -> p))
                                .properties("subject", i -> i.keyword(p -> p))

                                .properties("unitlist", i -> i.text(p -> p
                                        .fields("keyword", r -> r.keyword(m -> m.normalizer("lowercase")))))


                                .properties("country", i -> i.keyword(p -> p))

                                .properties("zkyxiaolei", i -> i.keyword(p -> p))
                                .properties("beidadalei", i -> i.keyword(p -> p))
                                .properties("pubmedsubject", i -> i.keyword(p -> p))
                                .properties("dataname", i -> i.keyword(p -> p))
                                .properties("meshshow", i -> i.keyword(p -> p))

                                .properties("enkwshow", i -> i.keyword(p -> p))
                                .properties("cnkwshow", i -> i.keyword(p -> p))
                                .properties("enaushow", i -> i.keyword(p -> p))
                                .properties("cnaushow", i -> i.keyword(p -> p))
                                .properties("cnkiurl", i -> i.keyword(p -> p))

                                .properties("wanfanurl", i -> i.keyword(p -> p))
                                .properties("weipuurl", i -> i.keyword(p -> p))
                                .properties("zhonghuaurl", i -> i.keyword(p -> p))

                                .properties("title", i -> i.text(p -> p))
                                .properties("jour", i -> i.text(p -> p))
                                .properties("pubdate", i -> i.text(p -> p))
                                .properties("url", i -> i.text(p -> p))


                                .properties("domain", i -> i.text(p -> p
                                        .fields("keyword", r -> r.keyword(m -> m.normalizer("lowercase")))))
                                .properties("subdomain", i -> i.text(p -> p))
                                .properties("beidaxiaolei", i -> i.keyword(p -> p))

                                .properties("articletypeshow", i -> i.text(p -> p))
                                .properties("enabshow", i -> i.text(p -> p))
                                .properties("entishow", i -> i.text(p -> p))

                                .properties("enunitshow", i -> i.text(p -> p))
                                .properties("cnunitshow", i -> i.text(p -> p))
                                .properties("hexinlist", i -> i.text(p -> p.analyzer("ik_max_word").searchAnalyzer("ik_max_word").fields("keyword", r -> r.keyword(m -> m.normalizer("lowercase")))))
                                .properties("translatenum", i -> i.integer(p -> p))
                                /**
                                 * 域名,做反向代理用,也用作之间所本馆订购
                                 */
                                .properties("marklist", i -> i.text(p -> p.analyzer("ik_max_word").searchAnalyzer("ik_max_word").fields("keyword", r -> r.keyword(m -> m.normalizer("lowercase")))))
                                /**
                                 * 一篇文章对应的所有期刊的不同写法,但是在allsearch中,没有用到
                                 */
                                .properties("jourlist", i -> i.text(p -> p.analyzer("ik_max_word").searchAnalyzer("ik_max_word").fields("keyword", r -> r.keyword(m -> m.normalizer("lowercase")))))
                                /**
                                 * 主题词大类
                                 */
                                .properties("meshdalei", i -> i.text(p -> p.analyzer("ik_max_word").searchAnalyzer("ik_max_word").fields("keyword", r -> r.keyword(m -> m.normalizer("lowercase")))))
                                /**
                                 * 左侧过滤的期刊名字,和检索[TA]的字段
                                 */
                                .properties("journame", i -> i.text(p -> p
                                        .analyzer("ik_max_word")
                                        .searchAnalyzer("ik_max_word")
                                        .fields("suggest", l -> l.completion(u -> u.analyzer("ik_max_word")))
                                        .fields("wildcard", v -> v.wildcard(a -> a))
                                        .fields("keyword", r -> r.keyword(m -> m.normalizer("lowercase")))))

                                /**
                                 * 是否为中国人发文
                                 */
                                .properties("ischinese", i -> i.integer(p -> p))
                                /**
                                 * 用作is_scie标识
                                 */
                                .properties("isscie", i -> i.integer(p -> p))
                                /**
                                 * 用于科室项目的选定部门之后点击单位时候的检索
                                 */

                                .properties("unitdept", i -> i.text(p -> p
                                        .fields("keyword", r -> r.keyword(m -> m.normalizer("lowercase")))))

                ));

        // 打印结果
        System.out.println(createIndexResponse.acknowledged());
        EsClient.clientOff();

    }
}
